<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>

<script language="javascript">
<!--

	var grid_ae = null;
	$(function(){
		grid_ae = $("#info_list").ligerGrid({
				checkbox: true,
	            columns: [
	            { display: '信息id', name: 'id', isSort : false, width: 100 },
	            { display: '标题', name: 'title',isSort : false, width: 400 },
	            { display: '摘要', name: 'summary',isSort : false, width: 500 }, 
	            {
	            	display: '操作选项', 
	            	name: 'id',
	            	isAllowHide: false,
	            	isSort : false,
	            	width :　200,
					render: function (record, rowindex, value, column){
						var hyperlink = record.hyperlink;
						if(hyperlink == null || hyperlink==""){
							hyperlink = "/infoDetail.htm?id="+record.id;
						}else if(hyperlink.indexOf("http")==-1){
							hyperlink = "/" + hyperlink;
						}
						var html = '<a onclick="deleteInfo('+value+')" href="javascript:;">删除</a>'+
						'&nbsp;&nbsp;<a onclick="editInfo('+value+')" href="javascript:;">编辑</a>'+
						'&nbsp;&nbsp;<a target="_blank" href="'+hyperlink+'">预览</a>';
						return html; 
					}
	            }
	            ], 
	            pageSize:10,
	            root :'list',
	            record:'totalRecord',
	            url: "/misc/info/getInfo.htm", 
	            width: '99%',height:'99%',
	            isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,
	            toolbar: { items: [
                           { text: '增加', click: openAddInfo, icon: 'add' },
                           { line: true },
                           { text: '删除', click: batchDelete, icon: 'delete' }
                           ]
                           }
	        });
	
			
			$("#parent").ligerComboBox({
				width : 215,
				selectBoxWidth : 215,
				selectBoxHeight : 180,
				valueField : 'mark',
				textField : 'text',
				treeLeafOnly : false,
				tree : {
					checkbox : false,
					btnClickToToggleOnly : false,
					url : '/misc/cms/channelTree.htm'
				}
			});

	});
	//批量删除内容
	function batchDelete(){
		if(contentList.length==0){
			$.ligerDialog.warn("请选择删除项！");
			return;
		}
		$.ligerDialog.confirm('你真的要删除吗？', 
				function (yes){
					if(yes){
						$.post("/misc/info/deleteInfo.htm",{contentList : $.toJSON(contentList)},function(data){
							loadDate();
							grid_ae.loadServerData();
							if(data=="success"){
								$.ligerDialog.success("删除成功！");
							}else{
								$.ligerDialog.warn("系统有点抽经，请稍候重试！");
							}
						}); 
					}
				});
	}
	//打开添加信息页面
	function openAddInfo(){
		dialog_ae = $.ligerDialog.open({ height: 800,width:900, url: "/misc/info/toAddInfo.htm", isResize: true ,modal:true,title:'添加稿件'});
	}
	//删除信息
	function deleteInfo(infoId){
		$.ligerDialog.confirm('你真的要删除吗？', 
			function (yes){
				if(yes){
					$.post("/misc/info/deleteInfo.htm",{infoId:infoId},function(data){
						loadDate();
						if(data=="success"){
							$.ligerDialog.success("删除成功！");
						}else{
							$.ligerDialog.warn("系统有点抽经，请稍候重试！");
						}
					}); 
				}
			});
	}
	function editInfo(id){
		dialog_ae = $.ligerDialog.open({ height: 800,width:900, url: "/misc/info/editInfo.htm?id="+id, isResize: true ,modal:true,title:'编辑稿件'});
	}
	// 推送内容
	function tuiSong(){
		var channel = $("#parent").ligerGetComboBoxManager().getValue();
		if(channel == ""){
			$.ligerDialog.warn("请选择所属栏目！");
			return;
		}else if(contentList.length==0){
			$.ligerDialog.warn("请选择推送内容！");
			return;
		}
		var contentArr = [];
		for(var i=0; i<contentList.length; i++){
			contentArr.push({
				"id" : contentList[i].id,
				"title" : contentList[i].title,
				"summary" : contentList[i].summary,
				"content" : contentList[i].content,
				"picture" : contentList[i].picture,
				"hyperlink" : "infoDetail.htm?id="+contentList[i].id
			});
		}
		$("#tui_song").attr("onclick","");
		//提交数据
		$.post("/misc/cms/commendContent.htm",{
			contentList : $.toJSON(contentArr),
			channel : channel,
			tblName : "coolsk_info"
		},function(data){
			if(data=="error"){
				$.ligerDialog.warn("亲，系统现在有点抽经，这次操作没有成功！");
			}else if(data==0){
				$.ligerDialog.success("亲，"+contentList.length+"条内容推送成功！");
			}else if(contentList.length==data){
				$.ligerDialog.warn("亲，您推送的这"+contentList.length+"条内容该栏目已经有了，您还是换个吧！");
			}else{
				$.ligerDialog.success("亲，您推送的内容有"+data+"个该栏目已经有了，另外"+(contentList.length-data)+"条成功了！");
			}
			$("#tui_song").attr("onclick","tuiSong()");
			loadDate();
		});
	}
	function search(){
		grid_ae.options.parms = [{name:'title',value:$("#search_name").val()}];
		grid_ae.loadData();
	}
//-->
</script>
<table>
	<tr>
		<td>
			<div id="searchbar">
			   稿件名称：<input id="search_name" type="text" value="${name}"/>
			    <input id="btnOK" type="button" value="查询" onclick="search()" />
			</div>
		</td>
		<td><input type="text" id="parent"/><button onclick="tuiSong()" id="tui_song" style="position:relative;left:220px;top:-22px; margin:0 0 -20px 0;">推送</button></td>
	</tr>
</table>

<div id="info_list" style="margin:0; padding:0"></div>


